<template>
  <div class="setting-container" style="margin-left: auto">
    <!--全屏 -->
    <el-tooltip class="box-item" effect="dark" content="全屏" placement="bottom-end">
    <svg-icon :icon-class="isFullscreen ? 'exit-fullscreen' : 'fullscreen'" size="24px" @click="toggle"></svg-icon>
  </el-tooltip>
    <!-- 刷新 -->
    <el-tooltip class="box-item" effect="dark" content="刷新" placement="bottom-end">
      <svg-icon icon-class="refresh" size="24px" @click="updateRefresh"></svg-icon>
    </el-tooltip>
    <!-- 切换主题 -->
      <ThemeSelect />
  </div>

  <!-- 用户头像 -->
  <el-dropdown trigger="click">
    <div class="avatar-container" style="margin-left: auto">
      <img :src="appStore.getAssetsFile(avatar)" alt="" />
    </div>
    <template #dropdown>
      <el-dropdown-menu>
        <router-link to="/">
          <el-dropdown-item>
            <SvgIcon icon-class="homepage" size="24px" />
            {{ $t("navbar.dashboard") }}
          </el-dropdown-item>
        </router-link>
        <a target="_blank" href="https://gitee.com/liu_hua_gu/temaplate-vue">
          <el-dropdown-item>
            <SvgIcon icon-class="gitee" size="24px" />
            gitee
          </el-dropdown-item>
        </a>
        <el-dropdown-item divided @click="logout"> 退出 </el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import { storeToRefs } from "pinia";
import { useAppStore } from "@/store/modules/app";
import { useFullscreen } from "@vueuse/core";
import SvgIcon from "@/components/SvgIcon/index.vue";
import { ElMessageBox, ElMessage } from "element-plus";
import  ThemeSelect  from '@/components/themeSelect/index.vue'
import router from "@/router";
const appStore = useAppStore();

//@ts-ignore
const { device, avatar } = storeToRefs(appStore);

/**
 * vueUse 全屏
 */
const { isFullscreen, toggle } = useFullscreen();

/**
 * 注销
 */
function logout() {
  ElMessageBox.confirm("确定注销并退出系统吗？", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      appStore.logOut();
      router.push(`/login`);
      ElMessage({
        type: "success",
        message: "操作成功",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "操作取消",
      });
    });
}

const updateRefresh = () => {
  appStore.refresh = !appStore.refresh;
};
</script>
<style scoped>
.setting-container {
  display: flex;
  align-items: center;

  .setting-item {
    display: inline-block;
    width: 30px;
    height: 50px;
    line-height: 50px;
    color: var(--el-text-color-regular);
    text-align: center;
    cursor: pointer;

    &:hover {
      background: var(--el-disabled-bg-color);
    }
  }
}

a {
  text-decoration: none;
}

.avatar-container {
  display: flex;
  place-items: center center;
  margin: 0 5px;
  cursor: pointer;

  img {
    width: 40px;
    height: 40px;
    border-radius: 5px;
  }
}
</style>
